package handlers

import (
	"github.com/gin-gonic/gin"
	"tvmanage-sys/models"
)

func Add(c *gin.Context) {
	title := c.PostForm("title")
	cont := c.PostForm("cont")
	times := c.PostForm("times")
	if times == "" || cont == "" || title == "" {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "字段不可为空",
		})
		return
	}
	video := models.Video{
		Title: title,
		Cont:  cont,
		Times: times,
	}
	err := models.DB.Create(&video).Debug().Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "添加失败",
		})
		return
	} else {
		c.JSON(200, gin.H{
			"code": 200,
			"msg":  "添加成功",
		})
		return
	}
}
func List(c *gin.Context) {
	var video []models.Video
	models.DB.Find(&video)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "ok",
		"data": video,
	})
	return
}
